package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.system.domain.Posts;
import com.ruoyi.system.mapper.PostsMapper;
import com.ruoyi.system.mapper.SysUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.CommentsMapper;
import com.ruoyi.system.domain.Comments;
import com.ruoyi.system.service.ICommentsService;
import org.springframework.web.bind.annotation.PostMapping;

/**
 * 用户评论信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-03-08
 */
@Service
public class CommentsServiceImpl implements ICommentsService 
{
    @Autowired
    private CommentsMapper commentsMapper;

    @Autowired
    private SysUserMapper sysUserMapper;

    @Autowired
    private PostsMapper postsMapping;

    /**
     * 查询用户评论信息
     * 
     * @param commentId 用户评论信息主键
     * @return 用户评论信息
     */
    @Override
    public Comments selectCommentsByCommentId(Long commentId)
    {
        return commentsMapper.selectCommentsByCommentId(commentId);
    }

    /**
     * 查询用户评论信息列表
     * 
     * @param comments 用户评论信息
     * @return 用户评论信息
     */
    @Override
    public List<Comments> selectCommentsList(Comments comments)
    {
        List<Comments> comments1 = commentsMapper.selectCommentsList(comments);
        for (Comments comment : comments1) {
            SysUser sysUser = sysUserMapper.selectUserById(comment.getUserId());
            comment.setUserName(sysUser.getUserName());
            Posts posts = postsMapping.selectPostsByPostId(comment.getPostId());
            comment.setPostName(posts.getTitle());
        }
        return comments1;
    }

    /**
     * 新增用户评论信息
     * 
     * @param comments 用户评论信息
     * @return 结果
     */
    @Override
    public int insertComments(Comments comments)
    {
        return commentsMapper.insertComments(comments);
    }

    /**
     * 修改用户评论信息
     * 
     * @param comments 用户评论信息
     * @return 结果
     */
    @Override
    public int updateComments(Comments comments)
    {
        return commentsMapper.updateComments(comments);
    }

    /**
     * 批量删除用户评论信息
     * 
     * @param commentIds 需要删除的用户评论信息主键
     * @return 结果
     */
    @Override
    public int deleteCommentsByCommentIds(Long[] commentIds)
    {
        return commentsMapper.deleteCommentsByCommentIds(commentIds);
    }

    /**
     * 删除用户评论信息信息
     * 
     * @param commentId 用户评论信息主键
     * @return 结果
     */
    @Override
    public int deleteCommentsByCommentId(Long commentId)
    {
        return commentsMapper.deleteCommentsByCommentId(commentId);
    }
}
